package com.example.demo.controller;


import com.example.demo.service.UsersService;
import com.example.demo.vo.MyException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
public class UsersController {

    @Autowired
    private UsersService usersService;


    @RequestMapping("import")
    public String excelImport(@RequestBody @RequestParam(value="filename") MultipartFile file){


        int  result=0;
        try {
         result=  usersService.addUser(file);
        } catch (IOException e) {
            e.printStackTrace();
        }

        if (result>0){
            return "导入成功";
        }
        else {

            throw new MyException("数据有误，请修改后上传");
        }
    }
}
